import 'dotenv/config';

import { Module, Global, NestModule, MiddlewareConsumer, RequestMethod } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { TestModule } from '@src/modules/test/test.module';
import { AuthModule } from '@src/common/auth/auth.module';
import { UsersModule } from '@src/modules/users/users.module';
import { RedisClient } from '@src/common/providers/redisClient.service';
import { LoggerMiddleware } from '@src/common/middlewares/logger.middleware';
import { config } from "@src/config/index"

@Global()
@Module({
  imports: [
    TypeOrmModule.forRoot(config.orm),
    AuthModule,
    UsersModule,
    TestModule,
  ],
  controllers: [AppController],
  providers: [AppService, RedisClient],
  exports: [RedisClient]
})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    // consumer
    //   .apply(LoggerMiddleware, LoggerMiddleware)
    //   .exclude(
    //     { path: '/', method: RequestMethod.POST }
    //   )
    //   .forRoutes({ path: '/', method: RequestMethod.GET });

    consumer
      .apply(LoggerMiddleware)
      .exclude(
        { path: '/', method: RequestMethod.POST }
      )
      .forRoutes({ path: '/', method: RequestMethod.GET });

  }
}
